//
//  CellOfDetailsPageOfCellOfCollectionViewOfService.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/9.
//  Copyright © 2016年 KX. All rights reserved.
//
#import "FreeTravelMacro.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "CellOfDetailsPageOfCellOfCollectionViewOfService.h"
@interface CellOfDetailsPageOfCellOfCollectionViewOfService ()
@property (nonatomic, strong) UIImageView *imageViewOfPhoto;
@property (nonatomic, strong) UILabel *labelOfTitle;
@property (nonatomic, strong) UILabel *labelOfPrice;
@property (nonatomic, strong) UILabel *labelOfSold;
@property (nonatomic, strong) UILabel *labelOfMark;
@property (nonatomic, strong) UILabel *labelOfPromotxt ;
@end
@implementation CellOfDetailsPageOfCellOfCollectionViewOfService
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageViewOfPhoto = [[UIImageView alloc]init];
        self.labelOfPromotxt = [[UILabel alloc]init];
        self.labelOfTitle = [[UILabel alloc]init];
        self.labelOfPrice = [[UILabel alloc]init];
        self.labelOfSold = [[UILabel alloc]init];
        self.labelOfMark = [[UILabel alloc]init];
        [self.contentView addSubview:self.imageViewOfPhoto];
        [self.contentView addSubview:self.labelOfMark];
        [self.contentView addSubview:self.labelOfSold];
        [self.contentView addSubview:self.labelOfPrice];
        [self.contentView addSubview:self.labelOfTitle];
        [self.contentView addSubview:self.labelOfPromotxt];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self.imageViewOfPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).mas_offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-10);
        make.top.equalTo(self.contentView.mas_top).mas_offset(10);
        make.width.equalTo(self.contentView.mas_width).multipliedBy(0.3);
    }];
    if (self.labelOfPromotxt.text.length > 0) {
        [self.labelOfPromotxt mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.imageViewOfPhoto.mas_top).mas_offset(10);
            make.height.mas_offset(20);
            make.left.equalTo(self.imageViewOfPhoto.mas_left).mas_offset(-5);
            
            
        }];
        self.labelOfPromotxt.backgroundColor = [UIColor redColor];
        self.labelOfPromotxt.textColor = [UIColor whiteColor];
        self.labelOfPromotxt.font = [UIFont systemFontOfSize:12];
    }
    
    [self.labelOfTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageViewOfPhoto.mas_right).mas_offset(10);
        make.top.equalTo(self.contentView.mas_top).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
        make.height.mas_offset(40);
    }];
    self.labelOfTitle.font = [UIFont systemFontOfSize:15];
    self.labelOfTitle.numberOfLines = 0;
    [self.labelOfMark mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageViewOfPhoto.mas_right).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
        make.top.equalTo(self.labelOfTitle.mas_bottom).mas_offset(10);
    }];
    self.labelOfMark.textColor = [UIColor grayColor];
    self.labelOfMark.font = [UIFont systemFontOfSize:12];
    [self.labelOfPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
        make.height.mas_offset(10);
    }];
    self.labelOfPrice.textColor = [UIColor redColor];
    [self.labelOfSold mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageViewOfPhoto.mas_right).mas_offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-10);
        make.height.mas_offset(10);
    }];
    self.labelOfSold.textColor = [UIColor grayColor];
    self.labelOfSold.font = [UIFont systemFontOfSize:12];
    
}
- (void)setModel:(ServiceListModel *)model{
    _model = model;
    [self.imageViewOfPhoto sd_setImageWithURL:[NSURL URLWithString:model.photo]];
    self.labelOfMark.text = model.mark;
    self.labelOfSold.text = model.sold;
    if (model.price.length>0) {
        self.labelOfPrice.text = [NSString stringWithFormat:@"%@元起",model.price];
    }
    
    self.labelOfTitle.text = model.title;
    self.labelOfPromotxt.text = model.promotxt;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
